package algorithmTopics.string;

public class test2 {

    public static void main(String[] args) {
        test2 test2 = new test2();
        System.out.println(test2.reverse(-12340));
    }
    public int reverse(int x) {
        long res = 0;
        while (x != 0) {
            res = res * 10 + x % 10;
            //把最后一位移除
            x = x / 10;
        }
        return (int) res == res? (int) res:0;
    }

    /*public int reverse(int x) {
        boolean sign = false;
        if (x < 0) {
            sign = true;
            x = Math.abs(x);
        }
        int length = sizeOfInt(x);
        int[] temp = new int[length];
        //转为数组
        for (int i = 0; i < length; i++) {
            temp[i] = x % 10;
            x = x / 10;
        }
        //旋转
        x= 0;
        for (int i = 0; i < length; i++) {
            x += temp[i] *(Math.pow(10,length - i - 1));
        }
        return sign?-x:x;
    }
    //判断是几位
    final static int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
            99999999, 999999999, Integer.MAX_VALUE };
    public int sizeOfInt(int x) {
        for (int i = 0;; i++){
            if (x <= sizeTable[i]) {
                return i + 1;
            }
        }
    }*/

}
